<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>发表评论</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/style.css" />
    <link rel="stylesheet" type="text/css" href="../css/swiper.min.css" />
    <link rel="stylesheet" type="text/css" href="../css/layer.css" />
    <link rel="stylesheet" type="text/css" href="../css/mdw.css" />
    <script type="text/javascript" src="../script/api.js"></script>
    <script type="text/javascript" src="../script/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="../script/swiper.min.js"></script>
    <script type="text/javascript" src="../script/mobile.js"></script>
    <script type="text/javascript" src="../script/layer.js"></script>
    <script type="text/javascript" src="../script/mdw.js"></script>
    <script type="text/javascript" src="../script/jumpPage.js"></script>

</head>
<body>
    <header class="header">
        <div class="backPrevPage" onclick="historyBack()"></div>
        <div class="pageTitle">发表评论</div>
    </header>
    <section class="pePage HTML_BOX">
        <div class="bg-eee" style="border-bottom:.2rem solid #EEE ; "></div>
        <div class="plr wareInfo">
            <div class="wareImage">
                <img src="" />
            </div>
            <div class="">
                <div class="eva_title">评分：</div>
                <div class="evaLvl">
                    <i class="on" data-level="1"></i>
                    <i class="on" data-level="2"></i>
                    <i class="on" data-level="3"></i>
                    <i class="on" data-level="4"></i>
                    <i class="on" data-level="5"></i>
                </div>
            </div>
        </div>
        <div class="liuyanItem plr">
            <textarea style="width: 100%;" autoHeight="true" class="evaTextare" placeholder="分享你的购买心得" class="liuyanarea"></textarea>
        </div>
        <ul class="eva_imgs">
            <!-- <li><div class="close">x</div><img src="../image/addImg_icon.png" /></li>
            <li><div class="close">x</div><img src="../image/addImg_icon.png" /></li>
            <li><div class="close">x</div><img src="../image/addImg_icon.png" /></li> -->
        </ul>
        <div class="addImageBox">
            <div class="addWareImg">
                <img src="../image/addImg_icon.png"/>
            </div>
        </div>  
    </section>
    
    <section class="sectionH">
        
    </section>
    <section class="evasection">
        <div class="bg-eee" style="border-bottom:.2rem solid #EEE ; "></div>
        <div class="evaBottom">
            <div class="nm"><i></i>匿名</div>
            <div class="sub">提交</div>
        </div>
    </section>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript">
    var param ;
    var nm = 1;
    var icon_id = [];
    var id = 0;
    $(".evaLvl i").click(function(){
        var lvl = $(this).data("level");
        $(".evaLvl i").removeClass("on");
        console.log(lvl);
        $(".evaLvl i").each(function(i,item){
            if(i<lvl){
                $(item).addClass("on");
            }
        })
    })
    $(".sub").click(function(){
        var val = $("textarea").val();
        var sta = $(".evaLvl .on").length;
        var imgarr="";
        for(var i = 0;i<icon_id.length;i++){
            if(i==0){
                imgarr = ""+icon_id[i];
            }else{
                imgarr += ","+icon_id[i];
            }
        }
        var p = {
            token:token,
            product_id:param.id,
            star:sta,
            content:val,
            no_name:nm,
            imgarr:imgarr,
            order_id:id
        };
        getAjax(Interface.go_comment,p,function(res){
            pop.notice(res.msg,1,function(){
                api.sendEvent({
                    name: 'eva',
                    extra: {}
                });
                api.sendEvent({
                    name: 'duihuanyhq',
                    extra: {}
                });
                historyBack();
            });
        },function(res,err){})
    })

    apiready = function(){
        $api.fixStatusBar($api.dom('header'));
        api.setStatusBarStyle({
            color: '#fff',//设置APP状态栏背景色
            style: 'dark'
        });
        ifCnAndEn();
        param = api.pageParam.info;
        id = api.pageParam.order_id;
        console.log(JSON.stringify(param));
        $(".wareImage img").attr("src",getImg(param.icon));
    };

    //点击上传
    $(".addImageBox").click(function(){
        var buttons = ['拍照', '从手机相册选择'];
        var cancel='取消';
        var title = '上传图片';
        if(cnen==2){
            buttons = ['Photograph', 'Selection from Mobile Phone Album'];
            title = 'Upload pictures';
            cancel = 'Cancel';
        }
        api.actionSheet({
             title:title,
             cancelTitle: cancel,
             buttons: buttons,
        }, function(ret, err) {
             if (ret) {
                 getPicture(ret.buttonIndex);
             }
        });
    })
    function close_img(img,e){
        var news = [];
        for(var i = 0;i<icon_id.length;i++){
            if(icon_id[i]==img){
                deleteElement($(e).parent("li"));
            }else{
                news.push(icon_id[i]);
            }
        }
        icon_id = news;

    }
    function getPicture(sourceType) {
        if (sourceType == 1) { // 拍照
            if(hasPermissions_camas()){
                getXiangji();
            }else{
                if(hasPermissions_camas()){
                    getXiangji();
                }
            }
        } else if (sourceType == 2) { // 从相机中选择
            var has = hasPermissions('storage');
            if(has == false){
                api.requestPermission({
                    list: ['storage'],
                    code: 100001
                }, function(ret, err){
                    console.log(JSON.stringify(ret));
                    var result = ret.list[0].granted;
                    var never = ret.never;
                    if (never == true && result == false){
                        api.toast({
                                msg:'请在设置中打开读取存储空间的权限',
                            });
                        return;
                    }
                    if(result == false){
                         return;
                    }
                    getDuqu();
                });
            }else{
                getDuqu();
            }
            //UIMediaScanner 是一个多媒体扫描器，可扫描系统的图片、视频等多媒体资源
        }
    }
    function getDuqu(){
        var texts =  {
                    stateText: '已选择*项',
                    cancelText: '取消',
                    finishText: '完成'
                };
        if(cnen==2){
            texts = {//（可选项）模块各部分的文字内容
                    stateText: '* items have been selected',
                    cancelText: 'Cancel',
                    finishText: 'Confirm'
                }
        }
        var obj = api.require('UIMediaScanner');
        obj.open({
            type: 'all',//返回的资源种类,picture（图片）,video（视频）,all（图片和视频）
            column: 4,//（可选项）图片显示的列数，须大于1
            max: 1,
            sort: { //（可选项）图片排序方式,asc（旧->新）,desc（新->旧）
                key: 'time',
                order: 'desc'
            },
            texts: texts,
            styles: {
                bg: '#fff',
                mark: {
                    icon: '',
                    position: 'bottom_right',
                    size: 20
                },
                nav: {
                    bg: '#eee',
                    stateColor: '#000',
                    stateSize: 18,
                    cancleBg: 'rgba(0,0,0,0)',
                    cancelColor: '#000',
                    cancelSize: 18,
                    finishBg: 'rgba(0,0,0,0)',
                    finishColor: '#000',
                    finishSize: 18
                }
            }
        }, function(ret) {
            console.log(JSON.stringify(ret));
            if(ret.eventType=='cancel'){return;}
            if (ret) {
                if (ret.hasOwnProperty("list")) {
                    api.showProgress({
                        title: '正在上传...',
                        modal: true
                    });
                }
                console.log(ret);
                upload(ret.list[0].path,function(res){
                    icon_id =res.id;
                    $(".userTx").attr("src",getImg(res.pic)).load(function(){
                     pop.close();
                    });
                });
            }
        });
    }
    function getXiangji(){
        //获取一张图片
        api.getPicture({
            sourceType: 'camera',
            encodingType: 'png',
            mediaValue: 'pic',
            allowEdit: false,
            quality: 90,
            saveToPhotoAlbum: true
        }, function(ret, err) {
            if(ret.data==''){return;}
            if (ret) {
                var imgSrc = ret.data;
                if (imgSrc != "") {
                    //$api.attr(ele, 'src', imgSrc);
                }
                upload(ret.data,function(res){
                    icon_id =res.id;
                    $(".userTx").attr("src",getImg(res.pic)).load(function(){
                     pop.close();
                    });
                });
            }
        });
    }
    $(".nm").click(function(){
        if($(this).hasClass("on")){
            nm=1;
            $(this).removeClass("on");
        }else{
            nm=2;
            $(this).addClass("on");
        }
    })
    
</script>
<script type="text/javascript">
    function ifCnAndEn(){
        if(cnen==2){
           $(".pageTitle").html("Product Review");
           $("textarea").attr('placeholder','Share your purchase experience');
           $(".eva_title").html('Stars:');
           $(".nm").html('<i></i>Anonymous');
           $(".addWareImg img").attr('src','../image/addImg_iconen.png');
           $(".sub").html('Submit');
        }
    }
</script>
</html>